package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ReleaseStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class StringToReleaseStatusConverter implements Converter<String, ReleaseStatus> {
    @Override
    public ReleaseStatus convert(String source) {
        for (ReleaseStatus status : ReleaseStatus.values()) {
            if (status.getCode().equals(Integer.valueOf(source))) {
                return status;
            }
        }
        throw new IllegalArgumentException("传入参数类型错误！必须是1或者2");
    }
}
